<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="120px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="整车物料号:" prop="materialNo">
            <el-input v-model="formModel.materialNo" disabled>
              <el-button slot="append" type="primary" icon="el-icon-search" :disabled="disabledNo" @click="queryMaterialData"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="车辆照片代码:" prop="pictureNo">
            <el-input v-model="formModel.pictureNo" disabled>
              <el-button slot="append" type="primary" icon="el-icon-search" @click="queryPictureNo"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
    <el-dialog
      v-dialogDrag
      v-if="showMaterialData"
      :close-on-click-modal="false"
      title="物料主数据"
      :visible.sync="showMaterialData"
      width="90%"
      append-to-body
    >
      <material-data-dialog :edit-data="editData" @queryMaterialDataSuc="queryMaterialDataSuc" />
    </el-dialog>
    <el-dialog
      v-dialogDrag
      v-if="showPhotos"
      :close-on-click-modal="false"
      title="车辆照片信息"
      :visible.sync="showPhotos"
      width="90%"
      append-to-body
    >
      <vehicle-photos-dialog @queryPictureNoSuc="queryPictureNoSuc" />
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'VehiclePhotosConfigMnt',
    components: {
      MaterialDataDialog: () => import('@/views/dialog/material-data-dialog'),
      VehiclePhotosDialog: () => import('./vehicle-photos-dialog')
    },
    props: ['pageType', 'editData'],
    data() {
      return {
        disabledNo :false,
        showMaterialData:false,
        showPhotos:false,
        formModel: {
          rcrdId: '',
          materialNo: '',
          pictureNo: '',
        },
        rules: {

        }
      }
    },
    computed: {

    },
    mounted() {
      this.$form = this.$refs.form
      this.init()
    },
    methods: {
      init() {
        this.$form = this.$refs.form
        const { pageType, editData, formModel } = this
        if (pageType === 'edit') {
          this.assignData(editData, formModel)
          this.disabledNo = true
        }
        this.initRules()
      },
      closeDialog() {
        this.$parent.$emit('update:visible', false)
      },
      initRules() {
        const REQUIRED_MSG = this.CONST.REQUIRED_MSG
        this.rules = {
          materialNo: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
          pictureNo: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        }
        this.$nextTick(_ => {
          this.$form.clearValidate()
        })
      },
      handleSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            const { pageType, formModel } = this
            const param = { ...formModel }
            const operateType = pageType === 'edit' ? '02' : '01'
            param.operateType = operateType
            const url = '/tmBasVehiclePhotos/maintainTmBasVehiclePhotos'
            const tip = pageType === 'edit' ? '修改成功！' : '新增成功！'
            this.post(url, param).then(res => {
              this.$info(tip, () => {
                this.$emit('mntSuc', res)
                this.closeDialog()
              })
            })
          }
        })
      },
      queryMaterialData(){
        this.editData.materialTypeKey = 'car'
        this.showMaterialData = true
      },
      queryMaterialDataSuc(data){
        this.formModel.materialNo = data.materialNo
      },
      queryPictureNo(){
        this.showPhotos = true
      },
      queryPictureNoSuc(data){
        this.formModel.pictureNo = data.pictureNo
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
